package main

import (
	"fmt"
	"gitee.com/unitedrhino/protocol-wumei/service/pwumeisvr/internal/startup"
	"gitee.com/unitedrhino/share/utils"
	"github.com/zeromicro/go-zero/core/logx"

	"gitee.com/unitedrhino/protocol-wumei/service/pwumeisvr/internal/config"
	deviceauthServer "gitee.com/unitedrhino/protocol-wumei/service/pwumeisvr/internal/server/deviceauth"
	"gitee.com/unitedrhino/protocol-wumei/service/pwumeisvr/internal/svc"
	"gitee.com/unitedrhino/protocol-wumei/service/pwumeisvr/pb/pwumei"

	"github.com/zeromicro/go-zero/core/service"
	"github.com/zeromicro/go-zero/zrpc"
	"google.golang.org/grpc"
	"google.golang.org/grpc/reflection"
)

func main() {
	logx.DisableStat()
	var c config.Config
	utils.ConfMustLoad("etc/pwumei.yaml", &c)
	ctx := svc.NewServiceContext(c)
	startup.Init(ctx)
	s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
		pwumei.RegisterDeviceAuthServer(grpcServer, deviceauthServer.NewDeviceAuthServer(ctx))

		if c.Mode == service.DevMode || c.Mode == service.TestMode {
			reflection.Register(grpcServer)
		}
	})
	defer s.Stop()
	fmt.Printf("Starting rpc server at %s...\n", c.ListenOn)
	s.Start()
}
